# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
from elasticsearch import Elasticsearch
from baidunews.settings import ES_URL,ES_INDEX,ES_DOC_TYPE

class BaidunewsPipeline(object):
    def open_spider(self,spider):
        self.es = Elasticsearch(ES_URL,timeout=1000)

    def close_spider(self,spider):
        pass
    def process_item(self, item, spider):
        self.es.index(index=ES_INDEX,doc_type=ES_DOC_TYPE,id=item['url'],body=dict(item))
        return item
